#include <iostream>
#include <pthread.h>
#include <vector>
#include<unistd.h>
int NUM = 3;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
void *Func1(void *args)
{
    pthread_detach(pthread_self());
    uint64_t number = (uint64_t)args;
    std::cout << "thread: " << number << std::endl;
    while (true)
    {
        pthread_mutex_lock(&mutex);
        pthread_cond_wait(&cond, &mutex);
        std::cout << "thread: " << number << std::endl;
        pthread_mutex_unlock(&mutex);

    }
}

int main()
{
    std::vector<pthread_t *> ids;
    for (int i = 0; i < NUM; i++)
    {
        pthread_t *temp = new pthread_t();
        pthread_create(temp, nullptr, Func1, (void *)i);
        ids.push_back(temp);
    }

    while(1)
    {
        sleep(1);
        pthread_cond_signal(&cond);
        std::cout<<"signal one thread"<<std::endl;
    }

    for (std::size_t i = 0; i < ids.size(); i++)
    {
        pthread_join(*ids[i], nullptr);
    }
}